// pages/operation/classRecord/classRecordLostDetail/index.js
import Dialog from "@vant/weapp/dialog/dialog";
import { ClassModel } from "../../../../api/api-work/classModel.js";
const classModel = new ClassModel();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    id: "",
    className: "", // 班级名称
    lessonTime: "", // 上课时间
    classStartTime: "",
    classEndTime: "",
    teacherName: "", // 上课老师
    state: "", // 缺课状态
    courseName: "", // 消耗方式
    courseNameC: "", //授课课程
    classHour: "", // 应扣课时
    classHourPay: "", // 实扣课时
    completed: "",
    repairState: "",
    courseDatas: {},
    detail: null,
    orderNo: null,
    studentId: null,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  async onLoad(options) {
    const param = JSON.parse(options.param);
    console.log("param: ", param);
    wx.setNavigationBarTitle({
      title: param.studentName,
    });
    this.setData({
      id: param.id,
      className: param.className,
      lessonTime: param.classDate.split(" ")[0],
      classStartTime: param.classStartTime,
      classEndTime: param.classEndTime,
      teacherName: param.teacherName,
      state: param.state,
      courseName: param.courseName,
      courseNameC: param.courseNameC,
      classHour: param.classHour,
      classHourPay: param.classHourPay,
      completed: param.completed,
      repairState: param.repairState,
      courseDatas: param,
      detail: param.detail,
      orderNo: param.orderNo,
      studentId: param.studentId,
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {},

  // 插班补课
  joinClass() {
    const param = JSON.stringify(this.data.courseDatas);
    console.log("++++++++++++", param);
    wx.navigateTo({
      url: `/pages/operation/classRecord/classJoin/index?param=${param}`,
    });
  },

  // 标记已补
  handleMakeUp() {
    Dialog.confirm({
      title: "确认已补？",
    }).then(() => {
      classModel
        .updateOrderByIdApi({
          id: this.data.id,
          repairState: "0",
        })
        .then((res) => {
          wx.navigateBack();
        });
    });
  },

  handleDetail() {
    wx.navigateTo({
      url: `/pages/operation/classRecord/makeupDetail/index?orderNo=${this.data.orderNo}&studentId=${this.data.studentId}`,
    });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
});
